<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>菜鸟教程 React 实例</title>
    <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
  <script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
  </head>
 <body>
    <div id="example"></div>
    <!-- babel -->
    <script type="text/babel">
    var LifeCycle = React.createClass({
      getInitialState: function() {
        return {
          data:0
        }
      },
      setNumber: function() {
        this.setState({data:this.state.data + 1});
      },
      render: function() {
        return (
          <div>
            <button onClick={this.setNumber}>点击更新组件</button>
            <Component newNumber={this.state.data}></Component>
          </div>
          )
      }
    });
    var  Component = React.createClass({
      componentWillMount: function() {
        console.log('组件将要挂载');
      },
      componentDidMount: function() {
        console.log('组件完成挂载');
      },
      componentWillUpdate: function() {
        console.log('组件将要更新');
      },
      componentDidUpdate: function() {
        console.log('组件完成更新');
      },
      componentWillUnmount: function() {
        console.log('组件将被删除')
      },
      componentWillReceiveProps: function() {
        console.log('逐渐将接受属性');
      },
      shouldComponentUpdate: function(newProps, newState){
        return true;
      },
      render: function() {
        return <p>{this.props.newNumber}</p>;
      }
    })
    ReactDOM.render(
    <LifeCycle />,
    document.getElementById('example')
    )
    </script>
  </body>
</html>